#include <stdio.h>
#include <unistd.h>
#include "mpi.h"

int
main(int argc, char **argv)
{
	int size, rank;
	int a, b;
	
	MPI_Init(&argc, &argv);
	
	MPI_Comm_size(MPI_COMM_WORLD, &size);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);

	a = 42;
	b = 0;

	if (rank == 0)
	{
		printf("sleeping 5 seconds\n");
		sleep(5);
		MPI_Recv(&b, 1, MPI_INT, 1, 10, MPI_COMM_WORLD,
			MPI_STATUS_IGNORE);
		printf("received message %d\n", b);

                if (b == 42) {
                        printf("SUCCESS\n");
                }
	}
	else 
	{
		MPI_Send(&a, 1, MPI_INT, 0, 10, MPI_COMM_WORLD);
		printf("sent message %d\n", a);
	}
	
	
	MPI_Finalize();
	return 0;
}

